package service.impl;

import dao.mapper.PhotoMapper;
import models.Photo;
import service.PhotoService;

public class PhotoServiceImpl implements PhotoService {
    public PhotoMapper photoMapper;

    @Override
    public boolean uploadAndAddToAlbum(Integer albumId, Integer photoId, String photoName, String path, int size) {
        return false;
    }

    @Override
    public boolean deletePhoto(Integer pid) {
        photoMapper.DeletePhoto(pid);
        return true;
    }

    @Override
    public Photo[] getAlbumPhotos(Integer albumId) {
        return new Photo[0];
    }

    @Override
    public Photo getPhotoByPid(Integer pid) {
        return photoMapper.GetPhotoByPid(pid);
    }

    @Override
    public Integer likeImg(Integer pid) {
        Photo photo=photoMapper.GetPhotoByPid(pid);
        photo.setLikeNum(photo.getLikeNum()+1);
        updataPhoto(photo);
        return photo.getLikeNum();
    }

    private void updataPhoto(Photo photo) {
        photoMapper.UpdataPhoto(photo);
    }

}
